package com.example;

public class StringUtils {

    public static String reverse(String str) {
        if (str == null) return null;
        return new StringBuilder(str).reverse().toString();
    }

    public static boolean isPalindrome(String str) {
        if (str == null) return false;
        String cleaned = str.replaceAll("\\s+", "").toLowerCase();
        return cleaned.equals(reverse(cleaned));
    }

    public static int countWords(String str) {
        if (str == null || str.trim().isEmpty()) return 0;
        return str.trim().split("\\s+").length;
    }

    public static void displayFunctions() {
        System.out.println("\n=== 字符串工具功能 ===");
        System.out.println("1. 字符串反转: reverse(str)");
        System.out.println("2. 回文检测: isPalindrome(str)");
        System.out.println("3. 单词计数: countWords(str)");
    }
}